home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / printer / prt.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  3.9 KB  |  141 lines

  1. ;void  prt(strg,printer_codes);
  2. ;  char  *strg,*printer_codes;
  3.  
  4.     EXTRN  _memory_model:byte
  5.     EXTRN  _error_code:byte
  6.     EXTRN  _time_out:byte
  7.  
  8. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  9.     ASSUME  CS:_TEXT
  10.     PUBLIC  _prt
  11. _prt    proc near
  12.     jmp  short start    ;jump over local data
  13. delay    dw   ?            ;
  14. target    dw   ?            ;
  15. start:    push bp            ;
  16.     mov  bp,sp        ;
  17.     push di            ;
  18.     push si            ;
  19.     cmp  _memory_model,0    ;near or far?
  20.     jle  begin        ;jump if near
  21.     inc  bp            ;else add 2 to BP
  22.     inc  bp            ;
  23. begin:    mov  ah,1        ;BIOS func to init prtr
  24.     sub  dx,dx        ;choose LPT1
  25.     int  17h        ;initialize the prtr port
  26.     sub  ax,ax        ;clear AX
  27.     mov  es,ax        ;point ES to 0000:0000
  28.     mov  dx,es:[408h]    ;get LPT1 base address
  29.     push ds            ;save Turbo's DS
  30.     mov  _error_code,1    ;1 = printer error
  31.     mov  cl,_time_out    ;get _time_out seconds
  32.     cmp  _memory_model,2    ;data near or far?
  33.     jb   A0            ;jump if near    
  34.     les  di,dword ptr[bp+8]    ;ES:DI pts to printer codes
  35.     lds  si,dword ptr[bp+4] ;DS:SI pts to Strg        
  36.     jmp  short A00        ;
  37. A0:    mov  ax,ds        ;ES = DS
  38.     mov  es,ax        ;
  39.     mov  di,[bp+6]        ;NEAR case
  40.     mov  si,[bp+4]        ;
  41. A00:    sub  ax,ax        ;
  42.     mov  al,cl        ;time_out
  43.     or   al,al        ;don't allow zero
  44.     jnz  A1            ;
  45.     mov  al,3        ;default to 3 seconds
  46. A1:    mov  cl,18        ;18 ticks per second
  47.     mul  cl            ;
  48.     mov  cs:delay,ax    ;save count
  49.     cmp  byte ptr[si],0    ;test for null string
  50.     je   H1            ;
  51. B1:    mov  al,[si]        ;get a character
  52.     inc  si            ;forward Strg ptr for next time
  53.     cmp  al,0        ;end of string?
  54.     je   LX            ;
  55.     cmp  al,128        ;test if control code
  56.     jb   F1            ;jump if below range
  57.     cmp  al,159        ;test if above
  58.     ja   F1            ;jump if above
  59.     push cx            ;save Strg len ctr
  60.     push di            ;save array position
  61.     sub  al,128        ;count codes from 0
  62.     mov  cl,6        ;times six bytes
  63.     mul  cl            ;offset in PrinterCodes
  64.     add  di,ax        ;now ES:DI pts to code sequence
  65.     sub  cx,cx        ;clear CX
  66.     mov  cl,es:[di]        ;get string descriptor
  67.     jcxz E1            ;quit loop if null
  68. C1:    inc  di            ;forward ptr
  69.     mov  al,es:[di]        ;get code character
  70.     call Writeit        ;write the code
  71.     or   ah,ah        ;printer error?
  72.     jnz  D1            ;continue if not
  73.     add  sp,4        ;balance stack
  74.     jmp  short H1        ;quit routine
  75. D1:    loop C1            ;go do next
  76. E1:    pop  di            ;restore ptr to start of array
  77.     pop  cx            ;restore Strg len ctr
  78.     jmp  short G1        ;go get next char in Strg
  79. F1:    call Writeit        ;go write character
  80.     or   ah,ah        ;proc returned error?
  81.     jz   H1            ;quit if so
  82. G1:    jmp  short B1        ;go do next char
  83. LX:    pop  ds            ;
  84.     dec  _error_code    ;0 = all OK
  85.     jmp  short I1        ;
  86. H1:    pop  ds            ;
  87. I1:    pop  si            ;
  88.     pop  di            ;
  89.     pop  bp            ;
  90.     cmp  _memory_model,0    ;quit
  91.     jle  quit        ;
  92.     db   0CBh        ;RET far
  93. quit:    ret            ;RET near
  94. Writeit    PROC
  95.     out  dx,al        ;send to output data register
  96.     inc  dx            ;forward to status register
  97.     push cx            ;save string counter
  98.     call GetBiosCount    ;get timer reading
  99.     mov  bx,cx        ;make copy
  100.     add  cx,cs:delay    ;add delay count
  101.     cmp  bx,cx        ;if timer doesn't turn over...
  102.     jb   J1            ;go ahead
  103.     mov  cx,cs:delay    ;otherwise, extend delay
  104. J1:    mov  cs:target,cx    ;save target count on stack
  105. Wait:    in   al,dx        ;get status value
  106.     test al,8        ;test for printer error
  107.     jz   Error        ;
  108.     test al,80h        ;test for Printer Ready
  109.     jnz  Ready        ;jump if ready
  110. Error:    call GetBiosCount    ;
  111.     cmp  cx,cs:target    ;compare to target
  112.     jb   Wait        ;    
  113.     mov  bl,1        ;1 = error
  114.     pop  cx            ;restore string counter
  115.     mov  ah,0        ;return code for failure
  116.     jmp  short K1        ;return
  117. Ready:    pop  cx            ;restore string counter
  118.     inc  dx            ; output control register
  119.     mov  al,13        ;bits for strobe signal
  120.     out  dx,al        ;send the signal
  121.     dec  al            ;change to strobe OFF
  122.     out  dx,al        ;send the signal
  123.     dec  dx            ;point back to
  124.     dec  dx            ;  base address
  125.     mov  ah,1        ;return code for success
  126. K1:    ret              ;
  127. Writeit    endp
  128. GetBIOSCount PROC
  129.     push dx            ;return value in CX:DX
  130.     push ax            ;
  131.     sub  ah,ah        ;function number
  132.     int  1ah        ;get timer count
  133.     mov  cx,dx        ;low word in CX
  134.     pop  ax            ;
  135.     pop  dx
  136.     ret
  137. GetBIOSCount endp
  138. _prt    endp
  139. _TEXT    ENDS
  140.     END
  141.